package BinarySearch;

public class BinarySearch {
    public static void main(String[] args) {
    testBinarySearch();
     }
        public static int binarySearch ( int[] arr, int target){
            int i = 0, j = arr.length - 1;
            while (i <= j) {
                int m = (i + j) >>> 1;
                if (target < arr[m]) {
                    j = m - 1;
                } else if (arr[m] < target) {
                    i = m + 1;
                } else {
                    return m;
                }
            }
            return -1;
        }
       public static void testBinarySearch() {
        int[] arr = {1,2,5,7,14,17,18,23,30};
        System.out.println("数组下标:"+binarySearch(arr, 17));
       }
}